package com.tools.cleanmaster.model.db;

import android.database.Cursor;

import com.tools.cleanmaster.model.db.annotations.TrashDBAnnotation;
import com.tools.cleanmaster.model.db.annotations.Type;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class RegularTrashBean {

    @TrashDBAnnotation(name = "a", type = Type.IntData)
    public int id;

    @TrashDBAnnotation(name = "b", type = Type.StringData)
    public String itemName;

    @TrashDBAnnotation(name = "c", type = Type.StringData)
    public String pkgName;

    @TrashDBAnnotation(name = "d", type = Type.StringData)
    public String rootPath;

    @TrashDBAnnotation(name = "e", type = Type.StringData)
    public String regulars;

    @TrashDBAnnotation(name = "f", type = Type.StringData)
    public String alertInfo;

    @TrashDBAnnotation(name = "g", type = Type.IntData)
    public int isDeleteDir;

    @TrashDBAnnotation(name = "h", type = Type.IntData)
    public int contentType;

    @TrashDBAnnotation(name = "i", type = Type.IntData)
    public int hierarchy;
    @TrashDBAnnotation(name = "k", type = Type.IntData)
    public int lid = 1;

    @TrashDBAnnotation(name = "j", type = Type.IntData)
    public int mediaType;

    public static List<RegularTrashBean> fromCursor(Cursor cursor) {
        if (cursor == null || cursor.getCount() == 0) {
            return Collections.emptyList();
        }

        final int idIndex = cursor.getColumnIndexOrThrow("a");
        final int itemNameIndex = cursor.getColumnIndexOrThrow("b");
        final int pkgNameIndex = cursor.getColumnIndexOrThrow("c");
        final int rootPathIndex = cursor.getColumnIndexOrThrow("d");
        final int regularsIndex = cursor.getColumnIndexOrThrow("e");
        final int alterInfoIndex = cursor.getColumnIndexOrThrow("f");
        final int isDeleteDirIndex = cursor.getColumnIndexOrThrow("g");
        final int contentTypeIndex = cursor.getColumnIndexOrThrow("h");
        final int hierarchyIndex = cursor.getColumnIndexOrThrow("i");
        final int mediaTypeIndex = cursor.getColumnIndexOrThrow("j");
        final int lidIndex = cursor.getColumnIndexOrThrow("k");

        ArrayList<RegularTrashBean> beans = new ArrayList<RegularTrashBean>(cursor.getCount());
        while (cursor.moveToNext()) {
            RegularTrashBean bean = new RegularTrashBean();
            bean.id = cursor.getInt(idIndex);
            bean.itemName = cursor.getString(itemNameIndex);
            bean.pkgName = cursor.getString(pkgNameIndex);
            bean.rootPath = cursor.getString(rootPathIndex);
            bean.regulars = cursor.getString(regularsIndex);
            bean.alertInfo = cursor.getString(alterInfoIndex);
            bean.isDeleteDir = cursor.getInt(isDeleteDirIndex);
            bean.contentType = cursor.getInt(contentTypeIndex);
            bean.hierarchy = cursor.getInt(hierarchyIndex);
            bean.mediaType = cursor.getInt(mediaTypeIndex);
            bean.lid = cursor.getInt(lidIndex);
            beans.add(bean);
        }

        return beans;
    }
}